<!--
 * @description: 红星闪闪
 * @author: 陈锦
 * @Date: 2021-10-22 14:29:20
 * @LastEditTime: 2021-11-11 16:12:28
-->
<template>
	<view style="padding: 30upx" class="privacy-page">
		<u-navbar :is-back="false" title="隐私策略" :background="background" title-color="#fff" :border-bottom="false">
		</u-navbar>
		<view style="width: 100%; text-align: right; margin-bottom: 20upx; padding-top:22upx; color: #999"
			v-show="show">{{ time + '秒后自动关闭' }}</view>

		<rich-text :nodes="strings"></rich-text>
		<view class="foot-btn" v-if="!show">
			<view class="btns">
				<u-button type="primary" @click="handleAgree">同意</u-button>
				<u-button type="error" @click="handleDisagree">不同意</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		doc
	} from './doc_policy';
	export default {
		data() {
			return {
				strings: '',
				fromType: '',
				time: 10,
				show: false,
				timer: null,
				background: {
					backgroundColor: 'rgb(0, 113, 219)'
				}
			}
		},
		mounted() {
			// alert(456)
			console.log(this.$route.query,'this.$router.query')
		  // this.phoneNumberServer = new window.PhoneNumberServer();
		},
		onLoad(v) {
			console.log(v,'v999')
		},
		methods: {
			handleAgree() { //同意
					this.$router.push({
					   path:'/pages/H5Login/login',
					   query:{
						   flag: '1',
						   Phone:this.$route.query.Phone
					   }});
			},
			handleDisagree() { //不同意 退出app
                this.$router.push({
                   path:'/pages/H5Login/login',
                   query:{
                	   flag: '2',
					   Phone:this.$route.query.Phone
                   }});
				uni.setStorageSync('policy', false);
			},
		
		onShow() {
			this.time = 10;
			this.strings = doc;
		},
		onLoad(p) {
			if (p.type == 'userCenter') {
				this.fromType = 'userCenter';
			} else if (p.type == 'login') {
				this.fromType = 'login';
			}
			if (p.isFirst == '1') {
				this.show = true;
				this.timer = setInterval(() => {
					if (this.time == 0) {
						uni.setStorageSync('policy', true);
						clearInterval(this.timer);
						this.show = false;
					} else {
						this.time--;
					}
				}, 1000);
			}
		},
		onBackPress(e) {
			if (this.fromType == 'login') {
				// this.$u.route({ url: '/pages/login/index?flag=1' });
				// if (this.time < 6) {
				// 	uni.setStorageSync('policy', true);

				// 	this.$u.route({
				// 		type: 'redirectTo',
				// 		url: '/pages/login/index',
				// 		params: {
				// 			flag: '1',
				// 		},
				// 	});
				// } else {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '至少浏览5秒',
				// 		duration: 2000,
				// 	});
				// }

				// uni.navigateTo({
				//   url: '/pages/login/index?flag=1',
				// });
			} else if (this.fromType == 'userCenter') {
				uni.switchTab({
					url: '/pages/userCenter/userCenter',
				});
			}

			// 此处一定姚要return为true，否则页面不会返回到指定路径
			return true;
		},
		},
	};
</script>

<style lang="scss" scoped>
	// p {
	//     text-indent: 50upx;
	// }
	.privacy-page {
		position: relative;
		width: 100%;
		height: 100%;
	}

	.foot-btn {
		position: fixed;
		bottom: 40upx;
		left: 0;
		width: 100%;
		display: flex;
		justify-content: center;

		.btns {
			width: 400upx;
			display: flex;
		}
	}
</style>
